During conversion between different encodings of character data, especially for Asian character sets, (examples include UNICODE (2 bytes per character), ASCII (1 or 2 bytes per character), EBCDIC (1 or 2 bytes per character plus shift characters added between Latin and Asian characters), the number of bytes in a character string can change. In the MQSeries family of products produced by IBM, in common with many other systems for handling data, there is a structure comprising a list of strings, each string in the list being the same size. The MQSeries structure known as a PCF (Programmable Command Format) string list is a list of MQSeries objects such as queues, queue managers typically used for passing information from one MQSeries machine to another.
There is often a requirement to convert the strings from one format to another. This can result in changes to the lengths of the converted strings which must be subsequently padded so the converted strings all have the same length to make them more easily accessible.
Accordingly, the present invention provides a method in a computer system comprising an input buffer and an output buffer, a method of converting a plurality of strings stored in said input buffer to a plurality of evenly spaced strings in said output buffer comprising the steps of: first passing over said input buffer and, for each string having a string length in said input buffer: placing the string in said output buffer at a next available address, responsive to said string length being longer than a maximum string length, setting said maximum string length to said string length and setting said string as the last incorrectly placed string in the output buffer, incrementing the next available address in the output buffer by the maximum string length plus the product of any positive difference between the current string length and previous maximum string length and the number of strings already placed in the output buffer; and second passing over said output buffer from the last incorrectly placed string in a direction opposite said first passing step and, for each incorrectly placed string in said output buffer: moving the string within the output buffer to an address being a multiple of said maximum string length from the start of the output buffer, and a component cooperable with an input buffer and an output buffer in a computer system for converting a plurality of strings stored in said input buffer to a plurality of evenly spaced strings in said output buffer, comprising: means for first passing over said input buffer including: placing each string having a string length in said input buffer into said output buffer at a next available address, means, responsive to a string length being longer than a maximum string length, for setting said maximum string length to said string length and setting said string as the last incorrectly placed string in the output buffer, means for incrementing the next available address in the output buffer by the maximum string length plus the product of any positive difference between the current string length and previous maximum string length and the number of strings already placed in the output buffer; and means for second passing over said output buffer from the last incorrectly placed string in a direction opposite said first passing means including: means for moving each incorrectly placed string in said output buffer to an address being a multiple of said maximum string length from the start of the output buffer.
The present invention only requires one output buffer, two passes of the data and minimises the amount of data movement by making use of the best information available at any given time during conversion. The invention operates by predicting where each string should be placed in the output buffer based on the longest string found up to the point a string is encountered.